package com.heima.admin.service.impl;

import com.heima.admin.service.ChannelSerice;
import com.heima.apis.wemedia.IWemediaClient;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import com.heima.model.wemedia.dtos.ChannelDto;
import com.heima.model.wemedia.dtos.SaveChannelDto;
import com.heima.model.wemedia.pojos.WmChannel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ChannelSericeImpl implements ChannelSerice {

    @Autowired
    private IWemediaClient wemediaClient;

    @Override
    public ResponseResult list(ChannelDto dto) {
        ResponseResult responseResult = wemediaClient.selectAll(dto);
        return responseResult;

    }

    @Override
    public ResponseResult save(SaveChannelDto dto) {
        boolean flag = wemediaClient.saveChannel(dto);

        if (flag) {
            return ResponseResult.okResult("添加成功");
        }else {
            return ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR, "添加失败");
        }

    }

    @Override
    public ResponseResult update(WmChannel channel) {
        return wemediaClient.updateChannel(channel);
    }

    @Override
    public ResponseResult deleteChannel(Integer id) {
        return wemediaClient.deleteChannel(id);
    }
}
